<?php

namespace App\Http\Controllers\Login;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Service\Admin\AdminService;
use App\Http\Controllers\Controller;
use Session,Config;

class LoginController extends Controller
{
    public function login()
    {
        return view('Login.login');
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Laravel\Lumen\Http\Redirector|void
     * 登录
     */
    public function doLogin(Request $request)
    {

        $data['username'] = $request->input('username');
        $data['password'] = $request->input('password');

        $user = new AdminService();
        $ret =  $user->login($data);

        $result = [];
        if($ret['code'] == 0)
        {
            $result = $ret['data'];
            Session::put(Config::get('custom.setting.MEMBER_TOKEN'),$result['token']);
            Session::put(Config::get('custom.setting.MEMBER_INFO'),$result['username']);
            unset($ret['data']);
        }

        return $ret;
    }

    /**
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Laravel\Lumen\Http\Redirector|void
     *
     * 退出登录
     */
    public function logout()
    {
        $where = [];
        $where['token'] = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));

        Session::forget(Config::get('custom.setting.MEMBER_TOKEN'));
        return redirect('/');

    }



}
